function create_post()
{
	var table = document.getElementById('sort');
	var rows = table.firstChild.rows;
	for(i = 0; i < rows.length; i++)
  	{
  		prefix_group = rows[i].firstChild.firstChild.id;
  		group_table_rows = rows[i].firstChild.firstChild.firstChild.rows;
  		for(j = 1; j < group_table_rows.length; j++)
  		{
  			prefix_row = group_table_rows[j].id.substr(6,2);
  			rows_cells = group_table_rows[j].cells;
  			for(k = 0; k < rows_cells.length; k++)
  			{
  				final_id = prefix_group+prefix_row + rows_cells[k].firstChild.id.substr(2,2);
  				inputs = rows_cells[k].firstChild.getElementsByTagName("INPUT");
  				for(m = 0; m < inputs.length; m++)
	  			{
	  				if(inputs[m].type=='hidden')
	  				inputs[m].value = final_id;
	  			}
  			}
  		}
  	}
}



function move_table(id,move)
{
	table = document.getElementById(id);
	var new_id = parseInt(id)+move;
  	if(new_id >= 0)
  	{
  		if(String(new_id).length==1)
	  	new_id = '0'+String(new_id);
	  	new_table = document.getElementById(new_id);
	  	if(new_table != null)
	  	{
	  		var table_1 = new_table.cloneNode(true);
		  	var table_2 = table.cloneNode(true);
		  	table.removeChild(table.firstChild);
		  	new_table.removeChild(new_table.firstChild);
		  	table.appendChild(table_1.firstChild);
		  	new_table.appendChild(table_2.firstChild);
	  	}
  	}
}




function move_row(id,move)
{
    var row = document.getElementById(id);
  	var prefix = id.substr(0,4);
  	var prefix_group = id.substr(4,2);
  	var prefix_row = id.substr(6,2);
  	var new_id = parseInt(prefix_row)+move;
  	if(new_id >= 0)
  	{ 
	  	if(String(new_id).length==1)
	  	new_id = '0'+String(new_id);
	  	new_id = prefix +prefix_group+new_id;
	  	new_row = document.getElementById(new_id);
	  	if(new_row != null)
	  	{	
	  		if(move==1)
	  		{
	  			first_cell_row = row.firstChild.firstChild.id.substr(2,2);
	  		}
            else 
            {
            	first_cell_row = new_row.firstChild.firstChild.id.substr(2,2);
            }
            first_cell_row_num = parseInt(first_cell_row);
        
		  	var row_1 = new_row.cloneNode(true);
		  	var row_2 = row.cloneNode(true);
		  	for(i = 0; i < new_row.cells.length; i++)
		  	{new_row.removeChild(new_row.cells[i]);i--}
		  	for(i = 0; i < row.cells.length; i++)
		  	{row.removeChild(row.cells[i]);i--}
		  	

		  	if(move==-1)
		  	{
			  	for(i = 0; i < row_2.childNodes.length; )
			  	{
			  		new_row_id = first_cell_row_num;
			  		if(String(new_row_id).length==1)
		  			new_row_id = '0'+String(new_row_id);
		  			new_row_id = prefix_group+new_row_id;
			  		row_2.childNodes[i].firstChild.id = new_row_id;
			  		new_row.appendChild(row_2.childNodes[i]);
			  		first_cell_row_num++;
			  	}
			  	for(i = 0; i < row_1.childNodes.length;)
			  	{
			  		new_row_id = first_cell_row_num;
			  		if(String(new_row_id).length==1)
		  			new_row_id = '0'+String(new_row_id);
		  			new_row_id = prefix_group+new_row_id;
			  		row_1.childNodes[i].firstChild.id = new_row_id;
			  		row.appendChild(row_1.childNodes[i]);
			  		first_cell_row_num++;
			  	}
		  	}
		  	else
		  	{
			  	for(i = 0; i < row_1.childNodes.length; )
			  	{
			  		new_row_id = first_cell_row_num;
			  		if(String(new_row_id).length==1)
		  			new_row_id = '0'+String(new_row_id);
		  			new_row_id = prefix_group+new_row_id;
			  		row_1.childNodes[i].firstChild.id = new_row_id;
			  		row.appendChild(row_1.childNodes[i]);
			  		first_cell_row_num++;
			  	}
			  	
			  	for(i = 0; i < row_2.childNodes.length; )
			  	{
			  		new_row_id = first_cell_row_num;
			  		if(String(new_row_id).length==1)
		  			new_row_id = '0'+String(new_row_id);
		  			new_row_id = prefix_group+new_row_id;
			  		row_2.childNodes[i].firstChild.id = new_row_id;
			  		new_row.appendChild(row_2.childNodes[i]);
			  		first_cell_row_num++;
			  	}
		  		
		  	}


		 }	
  	}
}

function move_cell(id,move)
{
    var cell = document.getElementById(id);
  	var prefix_group = id.substr(0,2);
  	var prefix_cell = id.substr(2,2);
  	var new_id = parseInt(prefix_cell)+move;
  	if(new_id>=0)
	{
		if(String(new_id).length==1)
	  	new_id = '0'+String(new_id);
	  	new_id = prefix_group+new_id;
	  	new_cell = document.getElementById(new_id);
	  	if(new_cell != null)
	  	{
	  		if (new_cell.parentNode.parentNode.id == cell.parentNode.parentNode.id)
	  		{
	  			var cell_1 = cell.cloneNode(true);
		  		var cell_2 = new_cell.cloneNode(true);
		  		cell.removeChild(cell.firstChild);
		  		new_cell.removeChild(new_cell.firstChild);
		  		new_cell.appendChild(cell_1.firstChild);
		  		cell.appendChild(cell_2.firstChild);
	            return;
	  		}
	  		else
	  		{
	  			if(cell.parentNode.parentNode.cells.length>1)
	  			{
		  			var table = document.getElementById(prefix_group);
		  			if(move==1)
		  			index = new_cell.parentNode.parentNode.rowIndex;
		  			else
		  			index = cell.parentNode.parentNode.rowIndex;
		  			var new_row = table.firstChild.insertRow(index);
		  		    var new_row_cell = document.createElement("td");
		  			
		  			new_row_id = new_cell.parentNode.parentNode.id;
		  			new_row_id_num =  parseInt(new_row_id.substr(6,2));
		  			current_id_num =  parseInt(cell.parentNode.parentNode.id.substr(6,2));
		  			
		  			
		  			var cell_1 = cell.cloneNode(true);
		  			cell.parentNode.parentNode.removeChild(cell.parentNode);
	
		  			table_rows = table.firstChild.childNodes;
		  			for(i = 0; i < table_rows.length; i++)
			  	    {
			  	    	var prefix_row = table_rows[i].id.substr(6,2);
			  	    	var num_prefix_row = parseInt(prefix_row);
			  	    	if(num_prefix_row>=new_row_id_num)
			  	    	{
			  	    		num_prefix_row++;
			  	    		if(String(num_prefix_row).length==1)
		  	                num_prefix_row = '0'+String(num_prefix_row);
			  	    		table_rows[i].id = 'row_'+prefix_group+num_prefix_row;
			  	    	}
	
			  	    }
			  	    
	                new_row.id = new_row_id;
	                new_row_cell.appendChild(cell_1);
		  			new_row.appendChild(new_row_cell);
	  			}
		  	    else
		  	    {
		  	    	var cell_1 = cell.cloneNode(true);
		  	    	if(move == 1)
		  	    	{var new_row_cell = new_cell.parentNode.parentNode.insertCell(0);}
		  	    	else
		  	    	{
			  	    	var new_row_cell = document.createElement("td");
			  	    	new_cell.parentNode.parentNode.appendChild(new_row_cell);
		  	    	}
		  	    	new_row_cell.appendChild(cell_1);
		  	    	cell.parentNode.parentNode.parentNode.removeChild(cell.parentNode.parentNode);
		  	    	var table = document.getElementById(prefix_group);
		  	    	table_rows = table.firstChild.childNodes;
		  	    	num_prefix_row =0;
			 		for(i = 1; i < table_rows.length; i++)
			     	{
			    		if(String(num_prefix_row).length==1)
		                num_prefix_row = '0'+String(num_prefix_row);
			    		table_rows[i].id = 'row_'+prefix_group+num_prefix_row;
			    		num_prefix_row++;
			     	}
		  	    }
	  			
	  		}

	  	}
	  	else
	  	{
	  		if(cell.parentNode.parentNode.cells.length>1)
	  			{
	  				 var new_row_cell = document.createElement("td");
	  				 current_row_id = cell.parentNode.parentNode.id;
	  				 var prefix_row = current_row_id.substr(6,2);
	  				 new_row_id =  parseInt(prefix_row)+1;
	  				 if(String(new_row_id).length==1)
	  				 new_row_id = '0'+String(new_row_id);
	  	             new_row_id = 'row_'+prefix_group+new_row_id;
	  	             var cell_1 = cell.cloneNode(true);
	  	             cell.parentNode.parentNode.removeChild(cell.parentNode);
	  	             var table = document.getElementById(prefix_group);
					 var new_row = table.insertRow(table.rows.length);	
					 new_row_cell.appendChild(cell_1);
					 new_row.id = new_row_id;
					 new_row.appendChild(new_row_cell); 
					 
					table_rows = table.firstChild.childNodes;
					num_prefix_row =0;
			 		for(i = 1; i < table_rows.length; i++)
			     	{
			    		if(String(num_prefix_row).length==1)
		                num_prefix_row = '0'+String(num_prefix_row);
			    		table_rows[i].id = 'row_'+prefix_group+num_prefix_row;
			    		num_prefix_row++;
			     	}

					 
					  			
	  			}
	  		
	  	}
	}
	else
	{	if(cell.parentNode.parentNode.cells.length>1)
	    {
			 var new_row_cell = document.createElement("td");
		     var cell_1 = cell.cloneNode(true);
		     cell.parentNode.parentNode.removeChild(cell.parentNode);
		     var table = document.getElementById(prefix_group);
			 var new_row = table.insertRow(1);	
			 new_row_cell.appendChild(cell_1);
			 new_row.appendChild(new_row_cell);
			 table_rows = table.firstChild.childNodes;
			 new_row.id = 'row_0000'; 
					num_prefix_row =0;
			 		for(i = 1; i < table_rows.length; i++)
			     	{
			    		if(String(num_prefix_row).length==1)
		                num_prefix_row = '0'+String(num_prefix_row);
			    		table_rows[i].id = 'row_'+prefix_group+num_prefix_row;
			    		num_prefix_row++;
			     	}
			    
	    }
		
		
		
	}
}